package com.cskaoyan.bean;

import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class GoodsGalleryList {

    private Integer id;

    private String goodsSn;

    private String name;

    private Integer categoryId;

    private Integer brandId;

    List<String> gallery;

    private String keywords;

    private String brief;

    private Boolean isOnSale;

    private Short sortOrder;

    private String picUrl;

    private String shareUrl;

    private Boolean isNew;

    private Boolean isHot;

    private String unit;

    private BigDecimal counterPrice;

    private BigDecimal retailPrice;

    private Date addTime;

    private Date updateTime;

    private Boolean deleted;

    private String detail;

    public static GoodsGalleryList generate(Goods goods) {

        GoodsGalleryList goodsGalleryList = new GoodsGalleryList();
        goodsGalleryList.id = goods.getId();
        goodsGalleryList.goodsSn = goods.getGoodsSn();
        goodsGalleryList.name = goods.getName();
        goodsGalleryList.categoryId = goods.getCategoryId();
        goodsGalleryList.brandId = goods.getBrandId();
        goodsGalleryList.keywords = goods.getKeywords();
        goodsGalleryList.brief = goods.getBrief();
        goodsGalleryList.isOnSale = goods.getIsOnSale();
        goodsGalleryList.sortOrder = goods.getSortOrder();
        goodsGalleryList.picUrl = goods.getPicUrl();
        goodsGalleryList.shareUrl = goods.getShareUrl();
        goodsGalleryList.isNew = goods.getIsNew();
        goodsGalleryList.isHot = goods.getIsHot();
        goodsGalleryList.unit = goods.getUnit();
        goodsGalleryList.counterPrice = goods.getCounterPrice();
        goodsGalleryList.retailPrice = goods.getRetailPrice();
        goodsGalleryList.addTime = goods.getAddTime();
        goodsGalleryList.updateTime = goods.getUpdateTime();
        goodsGalleryList.deleted = goods.getDeleted();
        goodsGalleryList.detail = goods.getDetail();

        //["http://yanxuan.nosdn.127.net/c41c58a7c72e8340211041cd493b1517.jpg", "http://yanxuan.nosdn.127.net/c41c58a7c72e8340211041cd493b1517.jpg", "http://yanxuan.nosdn.127.net/c41c58a7c72e8340211041cd493b1517.jpg", "http://yanxuan.nosdn.127.net/c41c58a7c72e8340211041cd493b1517.jpg", "http://yanxuan.nosdn.127.net/c41c58a7c72e8340211041cd493b1517.jpg"]
        List<String> galleryList = new ArrayList<>();
        String gallery = goods.getGallery();
        while (gallery.contains("jpg")||gallery.contains("png")) {
            int start = gallery.indexOf('"');
            gallery = gallery.substring(start + 1);
            int end = gallery.indexOf('"');
            String substring = gallery.substring(0, end);
            galleryList.add(substring);
            gallery = gallery.substring(end + 1);
        }
        goodsGalleryList.gallery = galleryList;
        return goodsGalleryList;
    }

}
